<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  data() {
    return {
      appWindow: window,
      form: {
        rightRuleName: "", //规则名称
        discountValue: "", //默认折扣
        isOpenDefault: 0, //开启状态
        discountType: 1, //折扣方式 打折
      },

      apiUrl: {
        create: "mall-site-portal/member-rights/createRule",
        detail: "mall-site-portal/member-rights/getRuleItem",
        update: "mall-site-portal/member-rights/updateRule",
      },
    };
  },
  methods: {
    async init() {
      console.log(this.rightId);
      console.log("rightType", this.rightType);

      // 拿到对应权益规则详情
      await this.mixinEdit_editBoxInit({
        model: "form",
        id: this.rightRuleId, //从 rule/home页传来
      });

      // 显示
      this.mixinEdit_editVisible = true;
    },

    // 输入框校验
    validator(rule, value, callback) {
      if (value > 10) {
        callback(new Error("最大折扣为10"));
      } else if (value === 0) {
        callback(new Error("最小折扣不能为0"));
      } else {
        this.$vFN.Tools.validateMoney(rule, value, callback);
      }
    },

    // 扩展   修改的请求添加参数
    mixinEdit_editFormSubmitExtend(data_) {
      data_.rightId = this.rightId;

      if (this.rightType == 1) {
        data_.discountValue = 10;
      }

      return data_;
    },

    //成功回调
    onSuccess() {},
  },
  mounted() {
    this.init();
  },
};
</script>
